package com.yztc.orangeentertainment.ui.main.subscribefragment.staritem.starfeedfragment;

import android.content.Context;
import android.os.Handler;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yztc.orangeentertainment.bean.staritembean.FeedListBean;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;
import com.yztc.orangeentertainment.utils.Okhttputils;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * Created by My on 2016/10/9.
 */
public class FeedModle implements FeedContract.Modle {
    @Override
    public void getStarFeedAll( String sid,int page,Context context ,final OnLoadFeedListener loadFeedListener) {
        try {
            Okhttputils.getRequestEnq(SubscribeUrlConfig.PATH.URL_FEED_FIRST+sid+"&ts=0&page="+page+SubscribeUrlConfig.PATH.URL_FEED_LAST, context, new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {

                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    String str=response.body().string();
                    String jsonString=str.substring(str.indexOf("(")+1,str.lastIndexOf(")"));
                    String obj= JSONObject.parseObject(jsonString).getString("data");
                    String obj2=JSONObject.parseObject(obj).getString("list");
                    if (obj2!=null) {
                        List<FeedListBean> list = JSONArray.parseArray(obj2, FeedListBean.class);
                        loadFeedListener.onSuccess(list);
                    }

                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
